<div class="container">
	<div class="bg-putih">
		<div class="jdl-page">
			<?php echo isset($judul)?$judul:'<font color="#ccc">Judul Belum Diberikan</font>'; ?>
			<div class="clearfix"></div>
		</div>

		<div id="analisis-obat">
			<table class="table table-hover table-bordered">
				<tr>
					<th>No</th>
					<th>Nama Obat</th>
					<th>Dosis</th>
					<th colspan="2">Interaksi</th>
				</tr>		

				<?php 
				$obat = $data['obat'];
				$dosis = $data['dosis'];
				$ord_number = 1;
				?>
				<?php for($count1=0; $count1<count($obat); $count1++): ?>
					<?php  
					$this->db->where('KdObat', $obat[$count1]);
					$q_obat = $this->db->get('obat');
					$r_obat = $q_obat->result_array();

					$kdobat = $r_obat[0]['KdObat'];
					$where = "KdObat = $kdobat OR KdObat2 = $kdobat";
					$this->db->where($where);
					$q_interaksi = $this->db->get('interaksi');
					$r_interaksi = $q_interaksi->result_array();
					?>

					<tr>
						<td width="5%" class="no-rowspan" rowspan="<?php echo count($r_interaksi); ?>"><?php echo $ord_number ?></td>
						<td width="15%" class="no-rowspan" rowspan="<?php echo count($r_interaksi);  ?>"><?php echo $r_obat[0]['NmObat'] ?></td>
						
						<?php if($dosis[$count1] >= $r_obat[0]['MinDosis'] && $dosis[$count1] <= $r_obat[0]['MaxDosis']): ?>
							<td class="text-success" rowspan="<?php echo count($r_interaksi); ?>">Dosis Sesuai, range ( <?php echo $r_obat[0]['MinDosis']." - ".$r_obat[0]['MaxDosis']." ".$r_obat[0]['SatuanDosis'] ?> )</td>
						<?php elseif($dosis[$count1] < $r_obat[0]['MinDosis'] ): ?>
							<td class="text-success" rowspan="<?php echo count($r_interaksi); ?>">Dosis Terlalu Sedikit, range ( <?php echo $r_obat[0]['MinDosis']." - ".$r_obat[0]['MaxDosis']." ".$r_obat[0]['SatuanDosis'] ?> )</td>
						<?php elseif($dosis[$count1] > $r_obat[0]['MinDosis'] ): ?>
							<td class="text-success" rowspan="<?php echo count($r_interaksi); ?>">Dosis Terlalu Banyak, range ( <?php echo $r_obat[0]['MinDosis']." - ".$r_obat[0]['MaxDosis']." ".$r_obat[0]['SatuanDosis'] ?> )</td>
						<?php endif; ?>
						
						<?php if(count($r_interaksi) > 0): ?>
							<?php $interkasi_count = 1; ?>

							<?php foreach($r_interaksi as $interaksi_row): ?>					
								<?php if($interkasi_count == 1): ?>
									<?php if($interaksi_row['KdObat'] != $kdobat): ?>
										<?php  
										$this->db->where('KdObat', $interaksi_row['KdObat']);
										$get_obat = $this->db->get('obat')->result_array();
										?>
										<td><?php echo $get_obat[0]['NmObat'] ?></td>
									<?php elseif($interaksi_row['KdObat2'] != $kdobat): ?>
										<?php  
										$this->db->where('KdObat', $interaksi_row['KdObat2']);
										$get_obat = $this->db->get('obat')->result_array();
										?>
										<td><?php echo $get_obat[0]['NmObat'] ?></td>
									<?php endif; ?>									
									<td><?php echo $interaksi_row['Interaksi'] ?></td></tr>

								<?php elseif($interkasi_count > 1): ?>
				

									<?php if($interaksi_row['KdObat'] != $kdobat): ?>
										<?php  
										$this->db->where('KdObat', $interaksi_row['KdObat']);
										$get_obat = $this->db->get('obat')->result_array();
										?>
										<td><?php echo $get_obat[0]['NmObat'] ?></td>
									<?php elseif($interaksi_row['KdObat2'] != $kdobat): ?>
										<?php  
										$this->db->where('KdObat', $interaksi_row['KdObat2']);
										$get_obat = $this->db->get('obat')->result_array();
										?>
										<td><?php echo $get_obat[0]['NmObat'] ?>aa</td>
									<?php endif; ?>
									<td><?php echo $interaksi_row['Interaksi'] ?></td>
									</tr>
								<?php endif; ?>

							<?php $interkasi_count++; ?>
						<?php endforeach; ?>
					<?php else: ?>
						<td colspan="2" align="center">Tidak ada interaksi</td></tr>
					<?php endif; ?>
					<?php $ord_number++ ?>
				<?php endfor; ?>
			</table>

			<div class="col-md-12" style="text-align: center; margin-top:15px;">
				<a href="<?php echo site_url('obat_analisa') ?>" class="btn btn-sm btn-primary"><i class="fa fa-arrow-left fa-fw"></i> Analisa obat yang lain</a>
			</div>
		</div>
		<div class="clearfix"></div>
	</div>
    </div> <!-- /container -->